<?php
namespace Home\Controller;
use Think\Controller;
class EditsectorController extends Controller {
    // 后台登录页
    public function index($id){
        if(isset($_SESSION['admin'])){ 

            $sector = D("sector");            
            $sectorList = $sector->where("id='$id'")->select();
            $this->assign('sectorId',$id);
            $sectorname = $sectorList[0]['name'];
            $this->assign('sectorName',$sectorname);
            $sectorinfo = $sectorList[0]['info'];
            $this->assign('sectorInfo',$sectorinfo);
           
            $this->display();
        }else{
            $url = 'http://localhost/sector/index.php/Home/Index/manage';
            header("location: $url");
        }
    }

     //职位信息编辑
    public function sectorEdit($id,$name,$info){
        if($id == null||$name == null || $info  == null){
            $result = array(
                'code'=> '1',
                'ext'=> 'error'
            );
            echo json_encode($result);
            return;
        }
        
        $sector = M("sector");
        $data['id'] = $id;
        $data['name'] = $name;
        $data['info'] = $info;
        $success = $sector->save($data);
        if($success){
            $result = array(
                'code'=> '0',
                'ext'=> 'success',
            );
            echo json_encode($result);
        }else {
            $result = array(
                'code'=> '1',
                'ext'=> 'fail'
            );
            echo json_encode($result);
        } 
    }
      //退出
    public function doLogout(){
        $_SESSION = array();
        if(isset($_COOKIE[session_name()])){
            setcookie(session_name(),'',time()-1,'/');
        }
        session_destroy();
        $this->redirect('Index/index');
    }
}
